// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.IndexManagement;

public sealed partial class SettingsSimilarityScripted : ISettingsSimilarity
{
	[JsonInclude, JsonPropertyName("script")]
	public Elastic.Clients.Elasticsearch.Script Script { get; set; }

	[JsonInclude, JsonPropertyName("type")]
	public string Type => "scripted";

	[JsonInclude, JsonPropertyName("weight_script")]
	public Elastic.Clients.Elasticsearch.Script? WeightScript { get; set; }
}

public sealed partial class SettingsSimilarityScriptedDescriptor : SerializableDescriptor<SettingsSimilarityScriptedDescriptor>, IBuildableDescriptor<SettingsSimilarityScripted>
{
	internal SettingsSimilarityScriptedDescriptor(Action<SettingsSimilarityScriptedDescriptor> configure) => configure.Invoke(this);

	public SettingsSimilarityScriptedDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Script ScriptValue { get; set; }
	private Elastic.Clients.Elasticsearch.Script? WeightScriptValue { get; set; }

	public SettingsSimilarityScriptedDescriptor Script(Elastic.Clients.Elasticsearch.Script script)
	{
		ScriptValue = script;
		return Self;
	}

	public SettingsSimilarityScriptedDescriptor WeightScript(Elastic.Clients.Elasticsearch.Script? weightScript)
	{
		WeightScriptValue = weightScript;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("script");
		JsonSerializer.Serialize(writer, ScriptValue, options);
		writer.WritePropertyName("type");
		writer.WriteStringValue("scripted");
		if (WeightScriptValue is not null)
		{
			writer.WritePropertyName("weight_script");
			JsonSerializer.Serialize(writer, WeightScriptValue, options);
		}

		writer.WriteEndObject();
	}

	SettingsSimilarityScripted IBuildableDescriptor<SettingsSimilarityScripted>.Build() => new()
	{
		Script = ScriptValue,
		WeightScript = WeightScriptValue
	};
}